package com.lagou.springboot_redisdemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @param
 * @author oyz
 * @version 1.0
 * @description: TODO
 * @date 2022/3/11 11:41
 */
@RestController
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    private RedisTemplate redisTemplate;


    @RequestMapping("/put")
    public String put(@RequestParam(required = true) String key,@RequestParam(required = true) String value){
        redisTemplate.opsForValue().set(key,value,20, TimeUnit.SECONDS);
        return "success";
    }

    @RequestMapping("/get")
    public String get(@RequestParam(required = true) String key){
       return (String) redisTemplate.opsForValue().get(key);
    }



}
